/**************************************************************************
	Replication do-file: "Corruption in Customs"
	Cyril Chalendard, Ana Fernandes, Gael Raballand and Bob Rijkers
	
	Created on: 01/07/2022
**************************************************************************/

clear all
set more off, perm
cap log close
cls

* Extra commands: remove the asterisk to install
*net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
*set scheme cleanplots, perm

* ----------------------- DIRECTORIES AND FOLDERS ----------------------- *

* Directories in which data are stored
global main "PUT YOUR DIRECTORY PATH HERE"
cd "$folder"

* Folders
global outputdata = "$main\Output Data"
cap mkdir "$main\Figures"
global figures = "$main\Figures"

* ----------------------------- BEGINS HERE ----------------------------- *

* -------
* Dataset
* -------
use "$outputdata\CFRR.dta", clear // open dataset

* Select sample
keep if sample_int==1 // keep relevant observations
keep if month_del>=-35 & month_del<=11 // keep relevant observations
replace wfr = . if month_del<0 // replace values for pre-delegated randomization period

* Collapse
global vars "sig_nr_rr_i sig_nr_i wfr"
collapse (mean) $vars , by(month_del) // collapse by counter

* Unit value
foreach x in $vars {
	replace `x' = `x'*100
}

* Panel dataset
tsset month_del // set panel variable


* ---------
* Figure A5
* ---------

twoway (connect sig_nr_i month_del, lcolor(gs10) lpattern(shortdash) lwidth(medthick) mcolor(gs10) msymbol(o) msize(small)) ///
		(connect sig_nr_rr_i month_del, lcolor(gs8) lpattern(dash) lwidth(medthick) mcolor(gs8) msymbol(s) msize(small)) ///
		(connect wfr month_del if month_del>=0 & month_del<=11, lcolor(gs6) lpattern(longdash) lwidth(medthick) mcolor(gs6) msymbol(X) msize(medsmall)), ///
		ylabel(, angle(0) labsize(small) nogrid) ///
		xline(0, lpattern(solid) lwidth(thin) lstyle(grid) lcolor(gs2)) ///
		xlabel(-35(5)11, nogrid) ///
		ytitle("% of declarations", size(small) color(black)) ///
		xtitle("Months since start of delegated randomization", size(small) color(black)) ///
		legend(pos(6) ring(10) col(2) order(1 "Significant excess interaction, inspector logits" 2 "Random excess interaction, inspector logits" 3 "Withdrawn from randomization") size(small)) ///
		name(Figure_A5, replace)
graph export "$figures\Figure_A5.eps", as(eps) replace
graph export "$figures\Figure_A5.pdf", as(pdf) replace


* -------------------------------- ENDS HERE -------------------------------- *